package com.reggie.module.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.reggie.common.ResultResponseVo;
import com.reggie.common.enums.backend.DishEnum;
import com.reggie.common.enums.backend.SetmealEnum;
import com.reggie.module.entity.dto.dishDto.DishStatusDto;
import com.reggie.module.entity.dto.setmealDto.SetmealDto;
import com.reggie.module.entity.dto.setmealDto.SetmealStatusDto;
import com.reggie.module.mapper.DishStatusDtoMapper;
import com.reggie.module.mapper.SetmealStatusDtoMapper;
import com.reggie.module.service.DishStatusService;
import com.reggie.module.service.SetmealStatusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author 早睡蛋
 * @Date 2022/9/24 16:55:24
 * @Desc:
 */
@Service
public class SetmealStatusServiceImpl extends ServiceImpl<SetmealStatusDtoMapper, SetmealStatusDto> implements SetmealStatusService {

    @Autowired
    private SetmealStatusDtoMapper setmealStatusDtoMapper;

    /**
     * 菜品 起售/停售
     * @param status
     * @param ids
     * @param request
     * @return
     */
    @Override
    public ResultResponseVo changeStatus(Integer status, List<Long> ids, HttpServletRequest request) {
        List<SetmealStatusDto> setmealStatusDtoList = new ArrayList<>();
        for (Long id : ids) {
            SetmealStatusDto setmealStatusDto = new SetmealStatusDto(id,status,request);
            setmealStatusDtoList.add(setmealStatusDto);
        }
        boolean updateBatchById = this.updateBatchById(setmealStatusDtoList);
        if (updateBatchById){
            return SetmealEnum.STATUS_IsCHANGE.getResultResponseVo();
        }
        return SetmealEnum.STATUS_IsNotCHANGE.getResultResponseVo();
    }

}
